<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="projectNum">
        <el-input
          v-model="queryParams.projectNum"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目类型" prop="projectType">
        <el-select v-model="queryParams.projectType" placeholder="请选择项目类型" clearable>
          <el-option
            v-for="dict in dict.type.project_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开始日期" prop="beginTime">
        <el-date-picker clearable
                        v-model="queryParams.beginTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择开始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期" prop="finishTime">
        <el-date-picker clearable
                        v-model="queryParams.finishTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="projectStatus">
        <el-select v-model="queryParams.projectStatus" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.project_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:project:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="ID" align="center" prop="projectId" />-->
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目编号" align="center" prop="projectNum" />
      <el-table-column label="项目类型" align="center" prop="projectType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_type" :value="scope.row.projectType"/>
        </template>
      </el-table-column>
      <el-table-column label="项目总款" align="center" prop="funds" />
      <el-table-column label="项目负责人" align="center" prop="functionary" />
      <el-table-column label="状态" align="center" prop="projectStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_status" :value="scope.row.projectStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="履约保证金" align="center" prop="bail" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleProject(scope.row)"
            v-hasPermi="['project:project:edit']"
          >实施</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectNum">
              <el-input v-model="form.projectNum" placeholder="请输入项目编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目类型" prop="projectType">
              <el-select v-model="form.projectType" placeholder="请选择项目类型(1中标，2其他)" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.project_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入项目地址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目总款" prop="funds">
              <el-input v-model="form.funds" placeholder="请输入项目总款" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目负责人" prop="functionary">
              <el-input v-model="form.functionary" placeholder="请输入项目负责人" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="开始日期" prop="beginTime">
              <el-date-picker clearable
                              v-model="form.beginTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择开始日期"
                              style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束日期" prop="finishTime">
              <el-date-picker clearable
                              v-model="form.finishTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择结束日期"
                              style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="交货期" prop="delivery">
              <el-input v-model="form.delivery" placeholder="请输入交货期" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="质保期" prop="guarantee">
              <el-input v-model="form.guarantee" placeholder="请输入质保期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="项目介绍" prop="introduction">
              <el-input v-model="form.introduction" placeholder="请输入项目介绍" type="textarea" :rows="3" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="优先级" prop="projectGrade">
              <el-radio-group v-model="form.projectGrade">
                <el-radio v-for="dict in dict.type.project_grade" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" type="textarea" :rows="3" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

<!--    实施对话框-->
    <el-dialog
      title=""
      :visible.sync="dialogVisible"
      width="1200px"
      :before-close="handleClose"
    >
      <div class="dialog-container">
        <!-- 顶部标签切换 -->
        <el-tabs
          v-model="activeTopTab"
          @tab-click="handleTopTabClick"
          class="top-tabs"
        >
          <el-tab-pane label="项目信息" name="project"></el-tab-pane>
          <el-tab-pane label="任务管理" name="task"></el-tab-pane>
        </el-tabs>

        <!-- 内容区布局：左侧菜单 + 右侧内容 -->
        <div class="content-wrapper">
          <!-- 左侧菜单 -->
          <el-menu
            :default-active="activeSubMenu"
            class="left-menu"
            @select="handleSubMenuSelect"
            background-color="#f5f7fa"
            text-color="#333"
            active-text-color="#1890ff"
            unique-opened
          >
            <!-- 项目信息子菜单 -->
            <template v-if="activeTopTab === 'project'">
              <el-menu-item index="view">项目查看</el-menu-item>
              <el-menu-item index="edit">项目修改</el-menu-item>
            </template>

            <!-- 任务管理子菜单 -->
            <template v-if="activeTopTab === 'task'">
              <el-menu-item index="progress">进度控制</el-menu-item>
              <el-menu-item index="add">任务添加</el-menu-item>
            </template>

          </el-menu>

          <!-- 右侧主内容区 -->
          <div class="main-content">
            <template v-if="activeTopTab === 'project'">

              <template v-if="activeSubMenu === 'view'">
              <!--       项目基本信息展示         -->
                <div class="project-info">
                  <!-- 基本信息区块 -->
                  <el-card shadow="hover" header="基本信息">
                    <el-descriptions :column="2" border>
                      <el-descriptions-item label="项目名称">{{ form.projectName }}</el-descriptions-item>
                      <el-descriptions-item label="项目编号">{{ form.projectNum }}</el-descriptions-item>
                      <el-descriptions-item label="项目地址">{{ form.address }}</el-descriptions-item>
                      <el-descriptions-item label="项目总金额">{{ form.funds }} 万元</el-descriptions-item>
                      <el-descriptions-item label="项目周期">{{ form.beginTime }}至{{ form.finishTime }}</el-descriptions-item>
                      <el-descriptions-item label="项目类型">
                        <dict-tag :options="dict.type.project_type" :value="form.projectType"/>
                      </el-descriptions-item>
                      <el-descriptions-item label="负责人">{{ form.functionary }}</el-descriptions-item>
                      <el-descriptions-item label="交货期">{{ form.delivery }}</el-descriptions-item>
                      <el-descriptions-item label="质保期">{{ form.guarantee }}</el-descriptions-item>
                      <el-descriptions-item label="优先级别">
                        <dict-tag :options="dict.type.project_grade" :value="form.projectGrade"/>
                      </el-descriptions-item>
                      <el-descriptions-item label="状态">
                        <dict-tag :options="dict.type.project_status" :value="form.projectStatus"/>
                      </el-descriptions-item>
                      <el-descriptions-item label="项目介绍" :span="2">
                        <div style="min-height: 60px;">{{ form.introduction || '暂无' }}</div>
                      </el-descriptions-item>
                      <el-descriptions-item label="备注" :span="2">
                        <div style="min-height: 60px;">{{ form.remark || '暂无' }}</div>
                      </el-descriptions-item>
                      <el-descriptions-item label="附件">{{ form.accessory || '暂无附件' }}</el-descriptions-item>
                    </el-descriptions>
                  </el-card>

                  <!-- 开票信息区块 -->
                  <el-card shadow="hover" header="开票信息" style="margin-top: 20px;">
                    <el-descriptions :column="2" border>
                      <el-descriptions-item label="开票名称">{{ form.invoiceName || '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="纳税人识别号">{{ form.invoiceNumber || '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="地址电话">{{ form.invoiceAddress || '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="开户行及账号">{{ form.invoiceBank || '未填写' }}</el-descriptions-item>
                    </el-descriptions>
                  </el-card>

                  <!-- 履约保证金缴纳情况区块 -->
                  <el-card shadow="hover" header="履约保证金缴纳情况" style="margin-top: 20px;">
                    <el-descriptions :column="3" border>
                      <el-descriptions-item label="缴纳金额">{{ form.bail && form.bail.money ? form.bail.money : '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="缴纳时间">{{ form.bail && form.bail.theTime ? form.bail.theTime :'未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="缴纳比例">{{ form.bail && form.bail.ratio ? form.bail.ratio : '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="退回金额">{{ form.bail && form.bail.backMoney ? form.bail.backMoney : '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="退回时间">{{ form.bail && form.bail.backTime ? form.bail.backTime : '未填写' }}</el-descriptions-item>
                      <el-descriptions-item label="备注" :span="3">
                        <div style="min-height: 60px;">{{form.bail && form.bail.remark ? form.bail.remark :'未填写' }}</div>
                      </el-descriptions-item>
                    </el-descriptions>
                  </el-card>
                </div>
              </template>
              <template v-if="activeSubMenu === 'edit'">
                <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="项目名称" prop="projectName">
                        <el-input v-model="form.projectName" placeholder="请输入项目名称" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="项目编号" prop="projectNum">
                        <el-input v-model="form.projectNum" placeholder="请输入项目编号" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="项目类型" prop="projectType">
                        <el-select v-model="form.projectType" placeholder="请选择项目类型(1中标，2其他)" style="width: 100%">
                          <el-option
                            v-for="dict in dict.type.project_type"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="项目地址" prop="address">
                        <el-input v-model="form.address" placeholder="请输入项目地址" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="项目总款" prop="funds">
                        <el-input v-model="form.funds" placeholder="请输入项目总款" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="项目负责人" prop="functionary">
                        <el-input v-model="form.functionary" placeholder="请输入项目负责人" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="开始日期" prop="beginTime">
                        <el-date-picker clearable
                                        v-model="form.beginTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="请选择开始日期"
                                        style="width: 100%">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="结束日期" prop="finishTime">
                        <el-date-picker clearable
                                        v-model="form.finishTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="请选择结束日期"
                                        style="width: 100%">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="交货期" prop="delivery">
                        <el-input v-model="form.delivery" placeholder="请输入交货期" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="质保期" prop="guarantee">
                        <el-input v-model="form.guarantee" placeholder="请输入质保期" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="项目介绍" prop="introduction">
                        <el-input v-model="form.introduction" placeholder="请输入项目介绍" type="textarea" :rows="3" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="优先级" prop="projectGrade">
                        <el-radio-group v-model="form.projectGrade">
                          <el-radio v-for="dict in dict.type.project_grade" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
                        </el-radio-group>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark" placeholder="请输入备注" type="textarea" :rows="3" />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <!-- 甲方开票信息 -->
                  <el-row :gutter="20" style="margin-top: 20px;">
                    <el-col :span="6">
                      <el-form-item label="开票名称" prop="invoiceName">
                        <el-input v-model="form.invoiceName" placeholder="请输入开票名" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="纳税人识别号" prop="invoiceNumber">
                        <el-input v-model="form.invoiceNumber" placeholder="请输入纳税人" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="地址电话" prop="invoiceAddress">
                        <el-input v-model="form.invoiceAddress" placeholder="请输入地址电" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="开户行及账号" prop="invoiceBank">
                        <el-input v-model="form.invoiceBank" placeholder="请输入开户行" />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <!-- 履约保证金缴纳情况 -->
                  <el-row :gutter="20" style="margin-top: 20px;">
                    <el-col :span="8">
                      <el-form-item label="缴纳金额" prop="bail.money">
                        <el-input v-model="form.bail.money" placeholder="请输入缴纳金额" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="缴纳时间" prop="bail.theTime">
                        <el-date-picker clearable
                                        v-model="form.bail.theTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="请选输入时间"
                                        style="width: 100%">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="缴纳比例" prop="bail.ratio">
                        <el-input v-model="form.bail.ratio" placeholder="请输入缴纳比例" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="8">
                      <el-form-item label="退回金额" prop="bail.backMoney">
                        <el-input v-model="form.bail.backMoney" placeholder="请输入退回金额" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="退回时间" prop="bail.backTime">
                        <el-date-picker clearable
                                        v-model="form.bail.backTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="请输入退回时间"
                                        style="width: 100%">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="备注" prop="bail.remark">
                        <el-input v-model="form.bail.remark" placeholder="请输入备注" />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <!-- 备注说明 -->
                  <el-row :gutter="20" style="margin-top: 10px; color: #f56c6c; font-size: 12px;">
                    <el-col :span="24">
                      <p>备注：缴纳金额为空状态即为未缴纳，退回金额为空即为状态为未退回</p>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item >
                        <el-button type="primary" @click="submitForm">提交</el-button>
                        <el-button @click="reset">重置</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </template>
            </template>

            <template v-if="activeTopTab === 'task'">
              <el-steps :active="projectTaskProgressMax" finish-status="success" align-center>
                <el-step title="沟通策划"></el-step>
                <el-step title="施工安装"></el-step>
                <el-step title="质量管控"></el-step>
                <el-step title="产品验收"></el-step>
                <el-step title="项目结算"></el-step>
              </el-steps>
              <template v-if="activeSubMenu === 'progress'">
                <div class="task-progress-container">
                  <!-- 需求沟通 -->
                  <el-card v-if="projectTaskList.filter(item => item.taskType === '1').length > 0" class="task-card" shadow="hover">
                    <div slot="header" class="task-card-header">
                      <span>1 需求沟通</span>
                    </div>
                    <div v-for="task in projectTaskList.filter(item => item.taskType === '1')" :key="task.taskId" class="task-item">
                      <el-card class="task-content-card" shadow="never">
                        <div slot="header" class="task-header">
                          <span class="task-title">{{ task.taskTitle }}</span>
                          <span class="task-date">创建日期：{{ parseTime(task.createTime, '{y}-{m}-{d}') }}</span>
                        </div>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">任务主题：</span>
                              <span class="value">{{ task.taskTitle }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">工作时间：</span>
                              <span class="value">{{ task.beginTime }} 至 {{ task.finishTime }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">优先级：</span>
                              <span class="value">{{ task.taskGrade === '1' ? '低' : task.taskGrade === '2' ? '中' : '高' }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">附件：</span>
                              <span class="value">{{ task.accessory ? '已上传' : '暂无附件'}}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">添加者：</span>
                              <span class="value">{{ task.createBy }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="24">
                            <div class="task-row">
                              <span class="label">工作描述：</span>
                              <span class="value">{{ task.description || '暂无描述' }}</span>
                            </div>
                          </el-col>
                        </el-row>
                      </el-card>
                    </div>
                  </el-card>

                  <!-- 方案策划 -->
                  <el-card v-if="projectTaskList.filter(item => item.taskType === '2').length > 0" class="task-card" shadow="hover">
                    <div slot="header" class="task-card-header">
                      <span>2 方案策划</span>
                    </div>
                    <div v-for="task in projectTaskList.filter(item => item.taskType === '2')" :key="task.taskId" class="task-item">
                      <el-card class="task-content-card" shadow="never">
                        <div slot="header" class="task-header">
                          <span class="task-title">{{ task.taskTitle }}</span>
                          <span class="task-date">创建日期：{{ parseTime(task.createTime, '{y}-{m}-{d}') }}</span>
                        </div>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">任务主题：</span>
                              <span class="value">{{ task.taskTitle }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">工作时间：</span>
                              <span class="value">{{ task.beginTime }} 至 {{ task.finishTime }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">优先级：</span>
                              <span class="value">{{ task.taskGrade === '1' ? '低' : task.taskGrade === '2' ? '中' : '高' }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">附件：</span>
                              <span class="value">{{ task.accessory ? '已上传' : '暂无附件'}}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">添加者：</span>
                              <span class="value">{{ task.createBy }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="24">
                            <div class="task-row">
                              <span class="label">工作描述：</span>
                              <span class="value">{{ task.description || '暂无描述' }}</span>
                            </div>
                          </el-col>
                        </el-row>
                      </el-card>
                    </div>
                  </el-card>

                  <!-- 采购备货 -->
                  <el-card v-if="projectTaskList.filter(item => item.taskType === '3').length > 0" class="task-card" shadow="hover">
                    <div slot="header" class="task-card-header">
                      <span>3 采购备货</span>
                    </div>
                    <div v-for="task in projectTaskList.filter(item => item.taskType === '3')" :key="task.taskId" class="task-item">
                      <el-card class="task-content-card" shadow="never">
                        <div slot="header" class="task-header">
                          <span class="task-title">{{ task.taskTitle }}</span>
                          <span class="task-date">创建日期：{{ parseTime(task.createTime, '{y}-{m}-{d}') }}</span>
                        </div>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">任务主题：</span>
                              <span class="value">{{ task.taskTitle }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">工作时间：</span>
                              <span class="value">{{ task.beginTime }} 至 {{ task.finishTime }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">优先级：</span>
                              <span class="value">{{ task.taskGrade === '1' ? '低' : task.taskGrade === '2' ? '中' : '高' }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">附件：</span>
                              <span class="value">{{ task.accessory ? '已上传' : '暂无附件'}}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">添加者：</span>
                              <span class="value">{{ task.createBy }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="24">
                            <div class="task-row">
                              <span class="label">工作描述：</span>
                              <span class="value">{{ task.description || '暂无描述' }}</span>
                            </div>
                          </el-col>
                        </el-row>
                      </el-card>
                    </div>
                  </el-card>

                  <!-- 施工安装 -->
                  <el-card v-if="projectTaskList.filter(item => item.taskType === '4').length > 0" class="task-card" shadow="hover">
                    <div slot="header" class="task-card-header">
                      <span>4 施工安装</span>
                    </div>
                    <div v-for="task in projectTaskList.filter(item => item.taskType === '4')" :key="task.taskId" class="task-item">
                      <el-card class="task-content-card" shadow="never">
                        <div slot="header" class="task-header">
                          <span class="task-title">{{ task.taskTitle }}</span>
                          <span class="task-date">创建日期：{{ parseTime(task.createTime, '{y}-{m}-{d}') }}</span>
                        </div>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">任务主题：</span>
                              <span class="value">{{ task.taskTitle }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">工作时间：</span>
                              <span class="value">{{ task.beginTime }} 至 {{ task.finishTime }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">优先级：</span>
                              <span class="value">{{ task.taskGrade === '1' ? '低' : task.taskGrade === '2' ? '中' : '高' }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">附件：</span>
                              <span class="value">{{ task.accessory ? '已上传' : '暂无附件'}}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">添加者：</span>
                              <span class="value">{{ task.createBy }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="24">
                            <div class="task-row">
                              <span class="label">工作描述：</span>
                              <span class="value">{{ task.description || '暂无描述' }}</span>
                            </div>
                          </el-col>
                        </el-row>
                      </el-card>
                    </div>
                  </el-card>

                  <!-- 质量管控 -->
                  <el-card v-if="projectTaskList.filter(item => item.taskType === '5').length > 0" class="task-card" shadow="hover">
                    <div slot="header" class="task-card-header">
                      <span>5 质量管控</span>
                    </div>
                    <div v-for="task in projectTaskList.filter(item => item.taskType === '5')" :key="task.taskId" class="task-item">
                      <el-card class="task-content-card" shadow="never">
                        <div slot="header" class="task-header">
                          <span class="task-title">{{ task.taskTitle }}</span>
                          <span class="task-date">创建日期：{{ parseTime(task.createTime, '{y}-{m}-{d}') }}</span>
                        </div>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">任务主题：</span>
                              <span class="value">{{ task.taskTitle }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">工作时间：</span>
                              <span class="value">{{ task.beginTime }} 至 {{ task.finishTime }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">优先级：</span>
                              <span class="value">{{ task.taskGrade === '1' ? '低' : task.taskGrade === '2' ? '中' : '高' }}</span>
                            </div>
                          </el-col>
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">附件：</span>
                              <span class="value">{{ task.accessory ? '已上传' : '暂无附件'}}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="12">
                            <div class="task-row">
                              <span class="label">添加者：</span>
                              <span class="value">{{ task.createBy }}</span>
                            </div>
                          </el-col>
                        </el-row>
                        <el-row :gutter="20">
                          <el-col :span="24">
                            <div class="task-row">
                              <span class="label">工作描述：</span>
                              <span class="value">{{ task.description || '暂无描述' }}</span>
                            </div>
                          </el-col>
                        </el-row>
                      </el-card>
                    </div>
                  </el-card>
                </div>
              </template>
              <template v-if="activeSubMenu === 'add'">
                <el-form ref="taskForm" :model="task" :rules="taskRules" label-width="100px">
                  <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="任务主题" prop="taskTitle">
              <el-input v-model="task.taskTitle" placeholder="请输入任务主题" />
            </el-form-item>
          </el-col>
                    <el-col :span="12">
            <el-form-item label="任务类型" prop="taskType">
              <el-select v-model="task.taskType" >
                <el-option v-for="dict in dict.type.task_type"
                           :value="dict.value"
                           :key="dict.value"
                           :label="dict.label"
                           />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="优先级" prop="taskGrade">
<!--              单选按钮-->
              <el-radio-group v-model="form.taskGrade">
                <el-radio v-for="dict in dict.type.project_grade"
                          :value="dict.value"
                          :key="dict.value"
                          :label="dict.label"
                          >
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
<!--                    协作人员-->
                    <el-col :span="12">
                      <el-form-item label="协作人员">
                        <el-input placeholder="请协作人员" v-model="task.collaborator">
                        </el-input>
                      </el-form-item>
                    </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="开始时间" prop="beginTime">
              <el-date-picker clearable
                              v-model="task.beginTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择开始时间"
                              style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
                  <el-form-item label="详细描述" prop="description">
                    <el-input v-model="task.content" placeholder="请输入详细描述" type="textarea" :rows="3" />
                  </el-form-item>
          </el-col>
        </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="备注" prop="description">
                        <el-input v-model="task.remark" placeholder="请输入备注" type="textarea" :rows="3" />
                      </el-form-item>
                    </el-col>
                  </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item>
              <el-button type="primary" @click="submitTaskForm">提交</el-button>

            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
              </template>
            </template>

          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listProject, getProject, delProject, addProject, updateProject, listTaskById} from "@/api/project/project"
import { listTask, listTaskByProjectId, getTask, addTask, updateTask, delTask } from "@/api/project/task"
import dict from "@/utils/dict";

export default {
  name: "Project",
  dicts: ['project_status', 'project_type', 'project_grade','task_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目管理表格数据
      projectList: [],
      //项目任务列表
      taskList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectNum: null,
        projectType: null,
        beginTime: null,
        finishTime: null,
        projectStatus: null,
      },
      // 表单参数
      form: {},
      // 任务表单参数
      task: {},
      // 表单校验
      rules: {
      },
      // 任务表单校验
      taskRules: {
      },
      //实施对话框参数
      dialogVisible: false,
      activeTopTab: 'project', // 顶部标签默认选中项目信息
      activeSubMenu: 'view'   , // 左侧菜单默认选中项目查看
      // 项目任务列表
      projectTaskList: [],
      //项目任务进度最大值
      projectTaskProgressMax:0,


    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询项目管理列表 */
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows
        this.projectList.filter(item => {
          item.bail=item.bail.money
        })
        this.total = response.total
        this.loading = false
      })
    },
    //根据项目id查询项目的所有任务
    getTaskList(projectId) {
      listTaskById(projectId).then(response => {
        this.projectTaskList = response.data
        this.task.projectId = projectId
        this.projectTaskProgressMax=0
        this.projectTaskList.forEach(item => {
          // 将 taskType 转换为数字进行比较
          const taskType = parseInt(item.taskType)
          const currentMax = parseInt(this.projectTaskProgressMax)

          if(taskType > currentMax && item.finishTime !== null){
            this.projectTaskProgressMax = item.taskType
          }

        })

      })
    },
    //点击实施
    handleProject(row) {
      this.dialogVisible = true
      this.reset()
      this.resetTask()
      this.projectTaskProgressMax=0
      const projectId = row.projectId || this.ids
      getProject(projectId).then(response => {
        this.form = response.data
        this.task.projectId = projectId
        this.getTaskList(projectId)
      })

    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        projectName: null,
        projectNum: null,
        projectType: null,
        address: null,
        funds: null,
        functionary: null,
        beginTime: null,
        finishTime: null,
        delivery: null,
        guarantee: null,
        introduction: null,
        projectGrade: null,
        projectStatus: null,
        contractId: null,
        invoiceName: null,
        invoiceNumber: null,
        invoiceAddress: null,
        invoiceBank: null,
        accessory: null,
        bail: {
          money: null,
          theTime: null,
          ratio: null,
          backMoney: null,
          backTime: null,
          remark: null
        },
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null

      }
      this.resetForm("form")
    },
    //重置任务表单
    resetTask() {
      this.task = {
        remark:null,
        taskId: null,
        taskTitle:null,
        taskType:null,
        taskGrade: null,
        collaborator: null,
        beginTime: null,
        content: null,
      }
      this.resetForm("task")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.projectId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加项目管理"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const projectId = row.projectId || this.ids
      getProject(projectId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改项目管理"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.projectId != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = row.projectId || this.ids
      this.$modal.confirm('是否确认删除项目管理编号为"' + projectIds + '"的数据项？').then(function() {
        return delProject(projectIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    },
    // 顶部标签切换时重置左侧菜单选中项
    handleTopTabClick(tab) {
      this.activeTopTab = tab.name
      // 根据顶部标签自动选中对应第一个子菜单
      switch(tab.name) {
        case 'project':
          this.activeSubMenu = 'view'
          break
        case 'task':
          this.activeSubMenu = 'progress'
          break
        case 'contract':
          this.activeSubMenu = 'list'
          break
      }
    },
    // 左侧菜单选择事件
    handleSubMenuSelect(key) {
      this.activeSubMenu = key
      // 可在这里添加内容区组件切换逻辑（如动态加载组件）
    },
    // 对话框关闭前回调
    handleClose(done) {
      done()
    },
    // 提交任务表单
    submitTaskForm(){
      this.$refs["taskForm"].validate(valid => {
        if (valid) {
          addTask(this.task).then(res => {
            this.$modal.msgSuccess("添加成功")
            this.dialogVisible = false
            this.getTaskList()
          })
        }
      })
    },

  }
}
</script>
<style scoped>
.dialog-container {
  padding: 10px 0;
}

.top-tabs {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e8e8e8;
}

.content-wrapper {
  display: flex;
  min-height: 400px; /* 固定最小高度，避免内容过短导致布局错乱 */
}

.left-menu {
  width: 180px;
  border-right: 1px solid #e8e8e8;
}

.main-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto; /* 内容过多时可滚动 */
}
.label-item {
  text-align: right;
  padding: 5px 0;
}
.value-item {
  text-align: left;
  padding: 5px 0;
}
</style>
